home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ue312src.zip / DISPLAY.C < prev    next >
C/C++ Source or Header  |  1993-04-21  |  57KB  |  2,161 lines

  1. /*
  2.  * The functions in this file handle redisplay. There are two halves, the
  3.  * ones that update the virtual display screen, and the ones that make the
  4.  * physical display screen the same as the virtual display screen. These
  5.  * functions use hints that are left in the windows by the commands.
  6.  *
  7.  */
  8.  
  9. #include    <stdio.h>
  10. #include    "estruct.h"
  11. #include    "eproto.h"
  12. #include    "edef.h"
  13. #include    "elang.h"
  14.  
  15. #define FARRIGHT    999        /* column beyond the right edge! */
  16.  
  17. #if     WINDOW_MSWIN
  18. static  int     foulcursor = FALSE;     /* see vtscreen() & movecursor() */
  19. #endif
  20.  
  21. static VIDEO   **vscreen;               /* Virtual screen. */
  22. #if    MEMMAP == 0
  23. static VIDEO   **pscreen;               /* Physical screen. */
  24. #endif
  25.  
  26. /*    some local function declarations    */
  27.  
  28. #if    PROTO
  29. #if    MEMMAP
  30. extern VOID PASCAL NEAR update_line(int row, struct VIDEO *vp1);
  31. #else
  32. extern VOID PASCAL NEAR update_line(int row, struct VIDEO *vp1, struct VIDEO *vp2);
  33. #endif
  34. extern VOID PASCAL NEAR update_hilite(void);
  35. #else
  36. extern VOID PASCAL NEAR update_line();
  37. extern VOID PASCAL NEAR update_hilite();
  38. #endif
  39.  
  40. /*
  41.  * Initialize the data structures used by the display code. The edge vectors
  42.  * used to access the screens are set up. The operating system's terminal I/O
  43.  * channel is set up. All the other things get initialized at compile time.
  44.  * The original window has "WFCHG" set, so that it will get completely
  45.  * redrawn on the first call to "update".
  46.  */
  47.  
  48. int PASCAL NEAR vtinit()
  49. {
  50.     register int i;
  51.     register VIDEO *vp;
  52.  
  53.     TTopen();        /* open the screen */
  54.     TTkopen();        /* open the keyboard */
  55.     TTrev(FALSE);
  56.  
  57.     /* allocate the virtual screen pointer array */
  58.     vscreen = (VIDEO **) malloc(term.t_mrow*sizeof(VIDEO *));
  59.     
  60.     if (vscreen == NULL)
  61. #if     WINDOW_MSWIN
  62.         return(FALSE);
  63. #else
  64.         meexit(1);
  65. #endif
  66.  
  67.  
  68. #if    MEMMAP == 0
  69.     /* allocate the physical shadow screen array */
  70.     pscreen = (VIDEO **) malloc(term.t_mrow*sizeof(VIDEO *));
  71.     if (pscreen == NULL)
  72. #if     WINDOW_MSWIN
  73.         return(FALSE);
  74. #else
  75.         meexit(1);
  76. #endif
  77. #endif
  78.  
  79.     /* for every line in the display */
  80.     for (i = 0; i < term.t_mrow; ++i) {
  81.  
  82.         /* allocate a virtual screen line */
  83.         vp = (VIDEO *) malloc(sizeof(VIDEO)+term.t_mcol);
  84.         if (vp == NULL)
  85. #if     WINDOW_MSWIN
  86.             return(FALSE);
  87. #else
  88.             meexit(1);
  89. #endif
  90.  
  91.         vp->v_flag = 0;        /* init change flags */
  92.         vp->v_left = FARRIGHT;    /* init requested rev video boundries */
  93.         vp->v_right = 0;
  94. #if    COLOR
  95.         vp->v_rfcolor = 7;    /* init fore/background colors */
  96.         vp->v_rbcolor = 0;
  97. #endif
  98.         /* connect virtual line to line array */
  99.         vscreen[i] = vp;
  100.  
  101. #if    MEMMAP == 0
  102.         /* allocate and initialize physical shadow screen line */
  103.         vp = (VIDEO *) malloc(sizeof(VIDEO)+term.t_mcol);
  104.         if (vp == NULL)
  105. #if     WINDOW_MSWIN
  106.             return(FALSE);
  107. #else
  108.             meexit(1);
  109. #endif
  110.  
  111.         vp->v_flag = VFNEW;
  112.         vp->v_left = FARRIGHT;
  113.         vp->v_right = 0;
  114. #if    INSDEL
  115.         vp->v_rline = i;    /* set requested line position */
  116. #endif
  117.         pscreen[i] = vp;
  118. #endif
  119.     }
  120.     return(TRUE);
  121. }
  122.  
  123. #if    CLEAN || WINDOW_MSWIN
  124. /* free up all the dynamically allocated video structures */
  125.  
  126. VOID PASCAL NEAR vtfree()
  127. {
  128.     int i;
  129.     for (i = 0; i < term.t_mrow; ++i) {
  130.         if (vscreen && vscreen[i]) free(vscreen[i]);
  131. #if    MEMMAP == 0
  132.         if (pscreen && pscreen[i]) free(pscreen[i]);
  133. #endif
  134.     }
  135.     if (vscreen) free(vscreen);
  136. #if    MEMMAP == 0
  137.     if (pscreen) free(pscreen);
  138. #endif
  139. }
  140. #endif
  141.  
  142. #if     WINDOW_MSWIN
  143. /* vtscreen:    map a screen into the Virtual Terminal system */
  144. /* ========                               */
  145.  
  146. VOID PASCAL NEAR vtscreen(SCREEN *sp)
  147. {
  148.     TTflush();
  149.     term.t_roworg = sp->s_roworg;
  150.     term.t_colorg = sp->s_colorg;
  151.     term.t_nrow = sp->s_nrow;
  152.     term.t_ncol = sp->s_ncol;
  153.  
  154.     vscreen = sp->s_virtual;
  155.     pscreen = sp->s_physical;
  156.     term.t_selscr(sp);
  157.     foulcursor = TRUE;
  158. } /* vtscreen */
  159.  
  160. /* vtinitscr: build a virtual terminal resource for a new screen */
  161. /* =========                                                     */
  162.  
  163. int PASCAL NEAR vtinitscr(SCREEN *sp, int nrow, int ncol)
  164.  
  165. /* returns TRUE if successful */
  166. {
  167.     int     result;
  168.  
  169.     if (nrow < 2) nrow = 2;
  170.     term.t_nrow = nrow;
  171.     term.t_ncol = ncol;
  172.     term.t_roworg = 0;
  173.     term.t_colorg = 0;
  174.     if ((result = vtinit()) == TRUE) {
  175.         sp->s_virtual = vscreen;
  176.         sp->s_physical = pscreen;
  177.         sp->s_nrow = nrow;
  178.         sp->s_ncol = ncol;
  179.         sp->s_roworg = 0;
  180.         sp->s_colorg = 0;
  181.     }
  182.     else {
  183.         vtfree();
  184.         sp->s_virtual = NULL;
  185.         sp->s_physical = NULL;
  186.     }
  187.     return result;
  188. } /* vtinitscr */
  189.  
  190. /* vtfreescr:  delete a virtual terminal resource for a dying screen */
  191. /* =========                                                         */
  192.  
  193. PASCAL NEAR vtfreescr(SCREEN *sp)
  194. {
  195.     vtscreen(sp);
  196.     vtfree();
  197.     vtscreen(first_screen);    /* switch to an existing screen */
  198. } /* vtfreescr */
  199.  
  200. /* vtsizescr:    resize the virtual terminal resources */
  201. /* =========                                          */
  202.  
  203. int PASCAL NEAR vtsizescr(SCREEN *sp, int nrow, int ncol)
  204.  
  205. /* returns TRUE if successful. Otherwise, the old VIDEO structures are
  206.    preserved. */
  207. {
  208.     VIDEO    **oldvvp, **oldpvp;
  209.     int     oldnrow, oldncol;
  210.  
  211.     oldvvp = sp->s_virtual;
  212.     oldpvp = sp->s_physical;
  213.     oldnrow = sp->s_nrow;
  214.     oldncol = sp->s_ncol;
  215.     if (vtinitscr(sp, nrow, ncol) == TRUE) {
  216.         /* success! let's free the old VIDEO structures */
  217.         WINDOW    *wp;
  218.         
  219.         vscreen = oldvvp;
  220.         pscreen = oldpvp;
  221.         term.t_nrow = oldnrow;
  222.         term.t_ncol = oldncol;
  223.         vtfree();        /* get rid of the old VIDEOs (kept up to now in
  224.                case the new allocation had failed) */
  225.         vtscreen(sp);    /* put the new VIDEOs into active duty */
  226.         for (wp = sp->s_first_window; wp != NULL; wp = wp->w_wndp) {
  227.             /* the VIDEOs have been wiped clean. Let's have every window
  228.                marked for a complete redraw */
  229.             wp->w_flag |= WFHARD|WFMODE;
  230.         }
  231.         term.t_sizscr(sp); /* resize the MDI window */
  232.         return(TRUE);
  233.     }
  234.     else {
  235.         /* failure! we still need some kind of VIDEO structures, so we
  236.             reuse the old ones */
  237.         term.t_nrow = oldnrow;
  238.         term.t_ncol = oldncol;
  239.         sp->s_virtual = vscreen = oldvvp;
  240.         sp->s_physical = pscreen = oldpvp;
  241.         mlabort(TEXT94);    /* "out of memory" */
  242.         return(FALSE);
  243.     }
  244. } /* vtsizescr */
  245. #endif
  246.  
  247. /*
  248.  * Clean up the virtual terminal system, in anticipation for a return to the
  249.  * operating system. Move down to the last line and clear it out (the next
  250.  * system prompt will be written in the line). Shut down the channel to the
  251.  * terminal.
  252.  */
  253. PASCAL NEAR vttidy()
  254. {
  255.     mlerase();
  256.     movecursor(term.t_nrow, 0);
  257.     TTflush();
  258.     TTclose();
  259.     TTkclose();
  260. }
  261.  
  262. /*
  263.  * Set the virtual cursor to the specified row and column on the virtual
  264.  * screen. There is no checking for nonsense values; this might be a good
  265.  * idea during the early stages.
  266.  */
  267. PASCAL NEAR vtmove(row, col)
  268.  
  269. int row, col;
  270.  
  271. {
  272.     vtrow = row;
  273.     vtcol = col;
  274. }
  275.  
  276. /* Write a character to the virtual screen. The virtual row and
  277.    column are updated. If we are not yet on left edge, don't print
  278.    it yet. If the line is too long put a "$" in the last column.
  279.    This routine only puts printing characters into the virtual
  280.    terminal buffers. Only column overflow is checked.
  281. */
  282.  
  283. PASCAL NEAR vtputc(c)
  284.  
  285. int c;
  286.  
  287. {
  288.     register VIDEO *vp;    /* ptr to line being updated */
  289.  
  290.     /* defeate automatic sign extenstion */
  291.     c = c & 0xff;
  292.  
  293.     /* this is the line to put this character! */
  294.     vp = vscreen[vtrow];
  295.  
  296.     if (c == '\t') {
  297.  
  298.         /* output a hardware tab as the right number of spaces */
  299.         do {
  300.             vtputc(' ');
  301.         } while (((vtcol + taboff) % (tabsize)) != 0);
  302.  
  303.     } else if (vtcol >= term.t_ncol) {
  304.  
  305.         /* we are at the right edge! */
  306.         ++vtcol;
  307.         vp->v_text[term.t_ncol - 1] = '$';
  308.  
  309.     } else if (disphigh && c > 0x7f) {
  310.  
  311.         /* char with high bit set is displayed
  312.            symbolically on 7 bit screens */
  313.         vtputc('^');
  314.         vtputc('!');
  315.         c -= 0x80;
  316.         if (c == '\t') {
  317.             vtputc('^');
  318.             vtputc('I');
  319.         } else
  320.             vtputc(c);
  321.  
  322.     } else if (c < 0x20 || c == 0x7F) {
  323.  
  324.         /* control character? */
  325.         vtputc('^');
  326.         vtputc(c ^ 0x40);
  327.  
  328.     } else {
  329.  
  330.         /* it's normal, just put it in the screen map */
  331.         if (vtcol >= 0)
  332.             vp->v_text[vtcol] = c;
  333.         ++vtcol;
  334.     }
  335. }
  336.  
  337. /*
  338.  * Erase from the end of the software cursor to the end of the line on which
  339.  * the software cursor is located.
  340.  */
  341. PASCAL NEAR vteeol()
  342. {
  343.     register VIDEO    *vp;
  344.  
  345.     vp = vscreen[vtrow];
  346.     while (vtcol < term.t_ncol) {
  347.         if (vtcol >= 0)
  348.         vp->v_text[vtcol] = ' ';
  349.     vtcol++;
  350.     }
  351. }
  352.  
  353. /* upscreen:    user routine to force a screen update
  354.         always finishes complete update     */
  355.  
  356. int PASCAL NEAR upscreen(f, n)
  357.  
  358. int f,n;    /* prefix flag and argument */
  359.  
  360. {
  361.     update(TRUE);
  362.     return(TRUE);
  363. }
  364.  
  365. /*
  366.  * Make sure that the display is right. This is a three part process. First,
  367.  * scan through all of the windows looking for dirty ones. Check the framing,
  368.  * and refresh the screen. Second, make sure that "currow" and "curcol" are
  369.  * correct for the current window. Third, make the virtual and physical
  370.  * screens the same.
  371.  */
  372. VOID PASCAL NEAR update(force)
  373.  
  374. int force;    /* force update past type ahead? */
  375.  
  376. {
  377.     register WINDOW *wp;
  378. #if     WINDOW_MSWIN
  379.     SCREEN  *sp;
  380. #endif
  381.  
  382. #if    TYPEAH
  383.     /* if we are not forcing the update, and there are keystrokes
  384.        waiting to be processed, skip the update */
  385.     if (force == FALSE && typahead())
  386.         return;
  387. #endif
  388.  
  389. #if    VISMAC == 0
  390.     /* if we are replaying a keyboard macro, don't bother keeping updated */
  391.     if (force == FALSE && kbdmode == PLAY)
  392.         return;
  393. #endif
  394.  
  395. #if     WINDOW_MSWIN
  396.     /* if we are not forcing the update, allow us to defer it */
  397.     if (force == FALSE) {
  398.         defferupdate = TRUE;
  399.         return;
  400.     }
  401.     else
  402.         defferupdate = FALSE;
  403.  
  404.     /* loop through all screens to update even partially hidden ones.
  405.        We update screens from back to front! */
  406.     sp = first_screen;
  407.     do {
  408.         char scroll_flag = 0;
  409.         int  scroll_fcol;
  410.         static WINDOW *scroll_wp = (WINDOW *)NULL;
  411.         
  412.         sp = sp->s_next_screen;
  413.         if (sp == (SCREEN *)NULL) {
  414.             sp = first_screen;
  415.             sp->s_cur_window = curwp; /* not always up to date */
  416.         }
  417.         vtscreen(sp);
  418.         wheadp = sp->s_first_window;
  419.         scroll_fcol = sp->s_cur_window->w_fcol;
  420. #endif
  421.     
  422.         /* update any windows that need refreshing */
  423.         wp = wheadp;
  424.         while (wp != NULL) {
  425.             if (wp->w_flag) {
  426.                 /* if the window has changed, service it */
  427.                 reframe(wp);    /* check the framing */
  428.                 if ((wp->w_flag & ~WFMODE) == WFEDIT)
  429.                     updone(wp);    /* update EDITed line */
  430.                 else if (wp->w_flag & ~WFMOVE)
  431.                     updall(wp);    /* update all lines */
  432.                 if (wp->w_flag & WFMODE)
  433.                     modeline(wp);    /* update modeline */
  434. #if WINDOW_MSWIN
  435.                 if (wp == sp->s_cur_window) {
  436.                     if (wp != scroll_wp) {
  437.                         /* switched to another window,
  438.                            force scroll bar updates */
  439.                         scroll_flag = WFHARD;
  440.                         scroll_wp = wp;
  441.                     } else
  442.                         scroll_flag = wp->w_flag & WFHARD;
  443.  
  444.                 }
  445. #endif
  446.                 wp->w_flag = 0;
  447.                 wp->w_force = 0;
  448.             }
  449.  
  450.             /* on to the next window */
  451.             wp = wp->w_wndp;
  452.         }
  453.  
  454.         /* recalc the current hardware cursor location */
  455. #if     WINDOW_MSWIN
  456.         if (sp == first_screen) {
  457. #endif
  458.             updpos();
  459.  
  460.             /* update the current window if we have to move it around */
  461.             if (curwp->w_flag & WFHARD)
  462.                 updall(curwp);
  463.             if (curwp->w_flag & WFMODE)
  464.                 modeline(curwp);
  465.             curwp->w_flag = 0;
  466.  
  467.             /* highlight region in the current window if needed */
  468.             update_hilite();
  469.  
  470. #if     WINDOW_MSWIN
  471.         }
  472. #endif
  473.  
  474. #if    MEMMAP
  475.         /* update the cursor and flush the buffers */
  476.         movecursor(currow, curcol - lbound);
  477. #endif
  478.  
  479.         /* check for lines to de-extend */
  480.         upddex();
  481.  
  482.         /* if screen is garbage, re-plot it */
  483.         if (sgarbf != FALSE)
  484.             if (gflags & GFSDRAW)
  485.                 sgarbf = FALSE;
  486.             else
  487.                 updgar();
  488.     
  489.         /* update the virtual screen to the physical screen */
  490.         updupd(force);
  491. #if     WINDOW_MSWIN
  492.         if (scroll_fcol != sp->s_cur_window->w_fcol) {
  493.             scroll_flag |= WFMOVE;
  494.         }
  495.         if (scroll_flag)
  496.             updscrollbars(sp, scroll_flag);
  497.  
  498.     } while (sp != first_screen);
  499.  
  500.     sgarbf = FALSE;
  501. #endif
  502.  
  503.     /* update the cursor and flush the buffers */
  504.     movecursor(currow, curcol - lbound);
  505.     TTflush();
  506.  
  507.     return;
  508. }
  509.  
  510. /*    reframe:    check to see if the cursor is on in the window
  511.             and re-frame it if needed or wanted        */
  512.  
  513. VOID PASCAL NEAR reframe(wp)
  514.  
  515. WINDOW *wp;
  516.  
  517. {
  518.     register LINE *lp;    /* search pointer */
  519.     register LINE *rp;    /* reverse search pointer */
  520.     register LINE *hp;    /* ptr to header line in buffer */
  521.     register LINE *tp;    /* temp debugging pointer */
  522.     register int i;        /* general index/# lines to scroll */
  523.     register int nlines;    /* number of lines in current window */
  524.  
  525.     /* figure out our window size */
  526.     nlines = wp->w_ntrows;
  527.     if (modeflag == FALSE)
  528.         nlines++;
  529.  
  530.     /* if not a requested reframe, check for a needed one */
  531.     if ((wp->w_flag & WFFORCE) == 0) {
  532.         lp = wp->w_linep;
  533.         for (i = 0; i < nlines; i++) {
  534.  
  535.             /* if the line is in the window, no reframe */
  536.             if (lp == wp->w_dotp)
  537.                 return;
  538.  
  539.             /* if we are at the end of the file, reframe */
  540.             if (lp == wp->w_bufp->b_linep)
  541.                 break;
  542.  
  543.             /* on to the next line */
  544.             lp = lforw(lp);
  545.         }
  546.     }
  547.  
  548.     /* reaching here, we need a window refresh */
  549.     i = wp->w_force;
  550.  
  551.     /* if smooth scrolling is enabled,
  552.         first.. have we gone off the top? */
  553.     if (sscroll && ((wp->w_flag & WFFORCE) == 0)) {
  554.         /* search thru the buffer looking for the point */
  555.         tp = lp = rp = wp->w_linep;
  556.         hp = wp->w_bufp->b_linep;
  557.         while ((lp != hp) || (rp != hp)) {
  558.  
  559.             /* did we scroll downward? */
  560.             if (lp == wp->w_dotp) {
  561.                 i = nlines - 1;
  562.                 break;
  563.             }
  564.  
  565.             /* did we scroll upward? */
  566.             if (rp == wp->w_dotp) {
  567.                 i = 0;
  568.                 break;
  569.             }
  570.  
  571.             /* advance forward and back */
  572.             if (lp != hp)
  573.                 lp = lforw(lp);
  574.             if (rp != hp)
  575.                 rp = lback(rp);
  576.  
  577.             /* problems????? */
  578.             if (lp == tp || rp == tp) {
  579.                 mlforce("BUG IN SMOOTH SCROLL--GET DAN!\n");
  580.                 TTgetc();
  581.             }
  582.         }
  583.     /* how far back to reframe? */
  584.     } else if (i > 0) {    /* only one screen worth of lines max */
  585.         if (--i >= nlines)
  586.             i = nlines - 1;
  587.     } else if (i < 0) {    /* negative update???? */
  588.         i += nlines;
  589.         if (i < 0)
  590.             i = 0;
  591.     } else
  592.         i = nlines / 2;
  593.  
  594.     /* backup to new line at top of window */
  595.     lp = wp->w_dotp;
  596.     while (i != 0 && lback(lp) != wp->w_bufp->b_linep) {
  597.         --i;
  598.         if (i < 0) {
  599.             mlforce("OTHER BUG IN DISPLAY --- GET DAN!!!\n");
  600.             TTgetc();
  601.         }
  602.         lp = lback(lp);
  603.     }
  604.  
  605.     /* and reset the current line at top of window */
  606.     wp->w_linep = lp;
  607.     wp->w_flag |= WFHARD;
  608.     wp->w_flag &= ~WFFORCE;
  609. }
  610.  
  611. /*    hilite:    in the current window, marks 10 and 11 are set and the
  612.         area between them is on screen, hilite that area    */
  613.  
  614. VOID PASCAL NEAR update_hilite()
  615.  
  616. {
  617.     int first_line;        /* first screen line to highlight */
  618.     short first_pos;    /* position in that line */
  619.     int last_line;        /* last screen line to highlight */
  620.     short last_pos;        /* position in that line */
  621.     LINE *forptr, *bckptr;    /* line pointers searching in current buffer */
  622.     int forline, bckline;    /* screen lines of for/bck ptrs */
  623.     int nlines;        /* number of text lines in current window */
  624.     LINE *first_mark;    /* first mark to highlighted text */
  625.     LINE *last_mark;    /* last mark to highlighted text */
  626.     LINE *b_linep;        /* header line of current buffer */
  627.     int temp_line;        /* temp line # for swap */
  628.     short temp_pos;        /*  more of the same */
  629.  
  630.     /* $hilight must be set to the first of 2 consecutive marks
  631.        used to define the region to highlight */
  632.     if (hilite > NMARKS)
  633.         return;
  634.  
  635.     /* Both marks must be set to define a highlighted region */
  636.     first_mark = curwp->w_markp[hilite];
  637.     last_mark = curwp->w_markp[hilite+1];
  638.     if ((first_mark == (LINE *)NULL) ||
  639.         (last_mark == (LINE *)NULL))
  640.             return;
  641.  
  642.     /* search for the two marks starting at the top line of this window */
  643.     first_pos = last_pos = -1;
  644.     forptr = curwp->w_linep;
  645.     bckptr = curwp->w_linep;
  646.     forline = bckline = 0;
  647.     b_linep = curwp->w_bufp->b_linep;
  648.     while (((first_pos == -1) || (last_pos == -1)) &&
  649.         ((forptr != (LINE *)NULL) || (bckptr != (LINE *)NULL))) {
  650.  
  651.         /* have we found either mark? */
  652.         if (forptr == first_mark) {
  653.             first_line = forline;
  654.             first_pos = findcol(forptr, curwp->w_marko[hilite]);
  655.         }
  656.         if (forptr == last_mark) {
  657.             last_line = forline;
  658.             last_pos = findcol(forptr, curwp->w_marko[hilite+1]);
  659.         }
  660.         if (bckptr == first_mark) {
  661.             first_line = bckline;
  662.             first_pos = findcol(bckptr, curwp->w_marko[hilite]);
  663.         }
  664.         if (bckptr == last_mark) {
  665.             last_line = bckline;
  666.             last_pos = findcol(bckptr, curwp->w_marko[hilite+1]);
  667.         }
  668.  
  669.         /* step outward one more line */
  670.         if (forptr != (LINE *)NULL) {
  671.             if (forptr != b_linep)
  672.                 forptr = lforw(forptr);
  673.             else
  674.                 forptr = (LINE *)NULL;
  675.             forline++;
  676.         }
  677.         if (bckptr != (LINE *)NULL) {
  678.             bckptr = lback(bckptr);
  679.             if (bckptr == b_linep)
  680.                 bckptr = (LINE *)NULL;
  681.             bckline--;
  682.         }
  683.     }
  684.  
  685.     /* if both lines are before the current window */
  686.     if ((first_line < 0) && (last_line < 0))
  687.         return;
  688.  
  689.     /* if both lines are after the current window */
  690.     nlines = curwp->w_ntrows;
  691.     if (modeflag == FALSE)
  692.         nlines++;
  693.     if ((first_line >= nlines) && (last_line >= nlines))
  694.         return;
  695.  
  696.     /* if we got them backwards, swap them around */
  697.     if ((first_line > last_line) ||
  698.         ((first_line == last_line) && (first_pos > last_pos))) {
  699.         temp_line = first_line;
  700.         first_line = last_line;
  701.         last_line = temp_line;
  702.         temp_pos = first_pos;
  703.         first_pos = last_pos;
  704.         last_pos = temp_pos;
  705.     }
  706.  
  707.     forptr = curwp->w_linep;
  708.     forline = curwp->w_toprow;
  709.     first_line += forline;
  710.     last_line += forline;
  711.     while (forline < curwp->w_toprow + nlines) {
  712.         if ((forline >= first_line) && (forline <= last_line)) {
  713.             vscreen[forline]->v_left = 0;
  714.             vscreen[forline]->v_right = findcol(forptr, lused(forptr));
  715.             if (forline == first_line)
  716.                 vscreen[forline]->v_left = first_pos;
  717.             if (forline == last_line)
  718.                 vscreen[forline]->v_right = last_pos;
  719.  
  720.             /* adjust for shifted window */
  721.             vscreen[forline]->v_left -= curwp->w_fcol;
  722.             vscreen[forline]->v_right -= curwp->w_fcol;
  723.  
  724.             /* adjust for shifted line */
  725.             if (vscreen[forline]->v_flag & VFEXT) {
  726.                 vscreen[forline]->v_left -= lbound;
  727.                 vscreen[forline]->v_right -= lbound;
  728.             }
  729.  
  730.                 } else {
  731.                         vscreen[forline]->v_left = FARRIGHT;
  732.                         vscreen[forline]->v_right = 0;
  733.                 }
  734.  
  735.                 /* step up one more line */
  736.                 if (forptr != b_linep)
  737.                         forptr = lforw(forptr);
  738.                 forline++;
  739.         }
  740.  
  741.         /* we need to flag a redraw to update the hilighted region */
  742.         curwp->w_flag |= WFHARD;
  743.         return;
  744. }
  745.  
  746. /*      updone: update the current line to the virtual screen           */
  747.  
  748. VOID PASCAL NEAR updone(wp)
  749.  
  750. WINDOW *wp;     /* window to update current line in */
  751.  
  752. {
  753.         register LINE *lp;      /* line to update */
  754.         register int sline;     /* physical screen line to update */
  755.         register int i;
  756.  
  757.         /* search down the line we want */
  758.         lp = wp->w_linep;
  759.         sline = wp->w_toprow;
  760.         while (lp != wp->w_dotp) {
  761.                 ++sline;
  762.                 lp = lforw(lp);
  763.         }
  764.  
  765.         /* and update the virtual line */
  766.         vscreen[sline]->v_flag |= VFCHG;
  767.         taboff = wp->w_fcol;
  768.         vtmove(sline, -taboff);
  769.  
  770.         /* move each char of line to virtual screen until at end */
  771.         for (i=0; i < lused(lp); ++i)
  772.                 vtputc(lgetc(lp, i));
  773. #if     COLOR
  774.         vscreen[sline]->v_rfcolor = wp->w_fcolor;
  775.         vscreen[sline]->v_rbcolor = wp->w_bcolor;
  776. #endif
  777.         vteeol();
  778.         taboff = 0;
  779. }
  780.  
  781. /*      updall: update all the lines in a window on the virtual screen */
  782.  
  783. VOID PASCAL NEAR updall(wp)
  784.  
  785. WINDOW *wp;     /* window to update lines in */
  786.  
  787. {
  788.         register LINE *lp;      /* line to update */
  789.         register int sline;     /* physical screen line to update */
  790.         register int i;
  791.         register int nlines;    /* number of lines in the current window */
  792.  
  793.         /* search down the lines, updating them */
  794.         lp = wp->w_linep;
  795.         sline = wp->w_toprow;
  796.         nlines = wp->w_ntrows;
  797.         if (modeflag == FALSE)
  798.                 nlines++;
  799.         taboff = wp->w_fcol;
  800.         while (sline < wp->w_toprow + nlines) {
  801.  
  802.                 /* and update the virtual line */
  803.                 vscreen[sline]->v_flag |= VFCHG;
  804.                 vscreen[sline]->v_left = FARRIGHT;
  805.                 vscreen[sline]->v_right = 0;
  806.                 vtmove(sline, -taboff);
  807.                 if (lp != wp->w_bufp->b_linep) {
  808.                         /* if we are not at the end */
  809.                         for (i=0; i < lused(lp); ++i)
  810.                                 vtputc(lgetc(lp, i));
  811.                         lp = lforw(lp);
  812.                 }
  813.  
  814.                 /* make sure we are on screen */
  815.                 if (vtcol < 0)
  816.                         vtcol = 0;
  817.  
  818.                 /* on to the next one */
  819. #if     COLOR
  820.                 vscreen[sline]->v_rfcolor = wp->w_fcolor;
  821.                 vscreen[sline]->v_rbcolor = wp->w_bcolor;
  822. #endif
  823.                 vteeol();
  824.                 ++sline;
  825.         }
  826.         taboff = 0;
  827. }
  828.  
  829. /*      updpos: update the position of the hardware cursor and handle extended
  830.                 lines. This is the only update for simple moves.        */
  831.  
  832. VOID PASCAL NEAR updpos()
  833.  
  834. {
  835.         register LINE *lp;
  836.         register int c;
  837.         register int i;
  838.  
  839.         /* find the current row */
  840.         lp = curwp->w_linep;
  841.         currow = curwp->w_toprow;
  842.         while (lp != curwp->w_dotp) {
  843.                 ++currow;
  844.                 lp = lforw(lp);
  845.         }
  846.  
  847.         /* find the current column */
  848.         curcol = 0;
  849.         i = 0;
  850.         while (i < curwp->w_doto) {
  851.                 c = lgetc(lp, i++);
  852.                 if (c == '\t')
  853.                         curcol += - (curcol % tabsize) + (tabsize - 1);
  854.                 else {
  855.                         if (disphigh && c > 0x7f) {
  856.                                 curcol += 2;
  857.                                 c -= 0x80;
  858.                         }
  859.                         if (c < 0x20 || c == 0x7f)
  860.                                 ++curcol;
  861.                 }
  862.                 ++curcol;
  863.         }
  864.  
  865.         /* adjust by the current first column position */
  866.         curcol -= curwp->w_fcol;
  867.  
  868.         /* make sure it is not off the left side of the screen */
  869.         while (curcol < 0) {
  870.                 if (curwp->w_fcol >= hjump) {
  871.                         curcol += hjump;
  872.                         curwp->w_fcol -= hjump;
  873.                 } else {
  874.                         curcol += curwp->w_fcol;
  875.                         curwp->w_fcol = 0;
  876.                 }
  877.                 curwp->w_flag |= WFHARD | WFMODE;
  878.         }
  879.  
  880.         /* if horizontall scrolling is enabled, shift if needed */
  881.         if (hscroll) {
  882.                 while (curcol >= term.t_ncol - 1) {
  883.                         curcol -= hjump;
  884.                         curwp->w_fcol += hjump;
  885.                         curwp->w_flag |= WFHARD | WFMODE;
  886.                 }
  887.         } else {
  888.         /* if extended, flag so and update the virtual line image */
  889.                 if (curcol >=  term.t_ncol - 1) {
  890.                         vscreen[currow]->v_flag |= (VFEXT | VFCHG);
  891.                         updext();
  892.                 } else
  893.                         lbound = 0;
  894.         }
  895. }
  896.  
  897. /*      upddex: de-extend any line that derserves it            */
  898.  
  899. VOID PASCAL NEAR upddex()
  900.  
  901. {
  902.         register WINDOW *wp;
  903.         register LINE *lp;
  904.         register int i,j;
  905.         register int nlines;    /* number of lines in the current window */
  906.  
  907.         wp = wheadp;
  908.  
  909.         while (wp != NULL) {
  910.                 lp = wp->w_linep;
  911.                 i = wp->w_toprow;
  912.                 nlines = wp->w_ntrows;
  913.                 if (modeflag == FALSE)
  914.                         nlines++;
  915.  
  916.                 while (i < wp->w_toprow + nlines) {
  917.                         if (vscreen[i]->v_flag & VFEXT) {
  918.                                 if ((wp != curwp) || (lp != wp->w_dotp) ||
  919.                                    (curcol < term.t_ncol - 1)) {
  920.                                         taboff = wp->w_fcol;
  921.                                         vtmove(i, -taboff);
  922.                                         for (j = 0; j < lused(lp); ++j)
  923.                                                 vtputc(lgetc(lp, j));
  924.                                         vteeol();
  925.                                         taboff = 0;
  926.  
  927.                                         /* this line no longer is extended */
  928.                                         vscreen[i]->v_flag &= ~VFEXT;
  929.                                         vscreen[i]->v_flag |= VFCHG;
  930.                                 }
  931.                         }
  932.                         lp = lforw(lp);
  933.                         ++i;
  934.                 }
  935.                 /* and onward to the next window */
  936.                 wp = wp->w_wndp;
  937.         }
  938. }
  939.  
  940. /*      updgar: if the screen is garbage, clear the physical screen and
  941.                 the virtual screen and force a full update              */
  942.  
  943. VOID PASCAL NEAR updgar()
  944.  
  945. {
  946.         register int i;
  947. #if     MEMMAP == 0
  948.         register int j;
  949.         register char *txt;
  950. #endif
  951.  
  952.         for (i = 0; i < term.t_nrow; ++i) {
  953.                 vscreen[i]->v_flag |= VFCHG;
  954. #if     COLOR
  955.                 vscreen[i]->v_fcolor = gfcolor;
  956.                 vscreen[i]->v_bcolor = gbcolor;
  957. #endif
  958. #if     MEMMAP == 0
  959.                 pscreen[i]->v_left = FARRIGHT;
  960.                 pscreen[i]->v_right = 0;
  961.                 txt = pscreen[i]->v_text;
  962.                 for (j = 0; j < term.t_ncol; ++j)
  963.                         txt[j] = ' ';
  964.                 pscreen[i]->v_flag &= ~VFNEW;
  965. #endif
  966.         }
  967.  
  968.         movecursor(0, 0);                /* Erase the screen. */
  969. #if     COLOR && WINDOW_MSWIN
  970.         TTforg(gfcolor);        /* inform the driver of the colors */
  971.         TTbacg(gbcolor);        /* to be used for erase to end of page */
  972. #endif
  973. #if REVSTA && WINDOW_MSWIN
  974.         TTrev(FALSE);
  975. #endif
  976.         TTeeop();
  977. #if     !WINDOW_MSWIN
  978.         sgarbf = FALSE;                  /* Erase-page clears */
  979.         mpresf = FALSE;                  /* the message area. */
  980. #endif
  981. #if     COLOR
  982.         mlerase();                      /* needs to be cleared if colored */
  983. #if     WINDOW_MSWIN
  984.         mpresf = FALSE;         /* MSWIN's message area handled differently.*/
  985. #endif
  986. #endif
  987. }
  988.  
  989. #if !WINDOW_MSWIN
  990. /*      for simple screen size changes (no window re-allocation involved)
  991.         do the following things
  992. */
  993.  
  994. VOID PASCAL NEAR update_size()
  995.  
  996. {
  997.         /* if we need the size update */
  998.         if ((first_screen->s_roworg != term.t_roworg) |
  999.             (first_screen->s_colorg != term.t_colorg) |
  1000.             (first_screen->s_nrow != term.t_nrow) |
  1001.             (first_screen->s_ncol != term.t_ncol)) {
  1002.  
  1003.                 /* reset the terminal drivers size concept */
  1004.                 term.t_roworg = first_screen->s_roworg;
  1005.                 term.t_colorg = first_screen->s_colorg;
  1006.                 term.t_nrow = first_screen->s_nrow;
  1007.                 term.t_ncol = first_screen->s_ncol;
  1008.  
  1009.                 /* make sure the update routines know we need a full update */
  1010.                 sgarbf = TRUE;
  1011.         }
  1012. }
  1013. #endif
  1014.  
  1015. /*      Display a pop up window.  Page it for the user.  Any key other
  1016.         than a space gets pushed back into the input stream to be interpeted
  1017.         later as a command.
  1018. */
  1019.  
  1020. #if     PROTO
  1021. int PASCAL NEAR pop(BUFFER *popbuf)
  1022. #else
  1023. int PASCAL NEAR pop(popbuf)
  1024.  
  1025. BUFFER *popbuf;
  1026. #endif
  1027. {
  1028.         register int index;     /* index into the current output line */
  1029.         register int llen;      /* length of the current output line */
  1030.         register int cline;     /* current screen line number */
  1031.         LINE *lp;       /* ptr to next line to display */
  1032.         int numlines;   /* remaining number of lines to display */
  1033.         int c;          /* input character */
  1034.  
  1035.         /* add the barrior line to the end of the pop up buffer */
  1036.         addline(popbuf, "------------------------------------------");
  1037.  
  1038.         /* set up to scan pop up buffer */
  1039.         lp = lforw(popbuf->b_linep);
  1040.         numlines = term.t_nrow-2;
  1041.         cline = 0;
  1042.     mmove_flag = FALSE;    /* disable mouse move events */
  1043.  
  1044.         while (lp != popbuf->b_linep) {
  1045.  
  1046.                 /* update the virtual screen image for this one line */
  1047.                 vtmove(cline, 0);
  1048.                 llen = lused(lp);
  1049.                 for (index = 0; index < llen; index++)
  1050.                         vtputc(lgetc(lp, index));
  1051.                 vteeol();
  1052. #if     COLOR
  1053.                 vscreen[cline]->v_rfcolor = gfcolor;
  1054.                 vscreen[cline]->v_rbcolor = gbcolor;
  1055. #endif
  1056.                 vscreen[cline]->v_left = FARRIGHT;
  1057.                 vscreen[cline]->v_right = 0;
  1058.                 vscreen[cline++]->v_flag |= VFCHG|VFCOL;
  1059.  
  1060.                 if (numlines-- < 1) {
  1061.  
  1062.                         /* update the virtual screen to the physical screen */
  1063.                         updupd(FALSE);
  1064.  
  1065.                         /* tell the user there is more */
  1066.                         mlwrite("--- more ---");
  1067.                         TTflush();
  1068.  
  1069.                         /* and see if they want more */
  1070.                         if ((c = tgetc()) != ' ') {
  1071.                                 cpending = TRUE;
  1072.                                 charpending = c;
  1073.                                 upwind();
  1074.  
  1075.                 /* re-enable mouse move events */
  1076.                 mmove_flag = TRUE;
  1077.                                 return(TRUE);
  1078.                         }
  1079.  
  1080.                         /* reset the line counters */
  1081.                         numlines = term.t_nrow-2;
  1082.                         cline = 0;
  1083.                 }
  1084.  
  1085.                 /* on to the next line */
  1086.                 lp = lforw(lp);
  1087.         }
  1088.         if (numlines > 0) {
  1089.  
  1090.                 /* update the virtual screen to the physical screen */
  1091.                 updupd(FALSE);
  1092.                 TTflush();
  1093.  
  1094.                 if ((c = tgetc()) != ' ') {
  1095.                         cpending = TRUE;
  1096.                         charpending = c;
  1097.                 }
  1098.         }
  1099.         upwind();
  1100.  
  1101.     /* re-enable mouse move events */
  1102.     mmove_flag = TRUE;
  1103.         return(TRUE);
  1104. }
  1105.  
  1106. /*      updupd: update the physical screen from the virtual screen      */
  1107.  
  1108. VOID PASCAL NEAR updupd(force)
  1109.  
  1110. int force;      /* forced update flag */
  1111.  
  1112. {
  1113.         register VIDEO *vp1;
  1114.         register int i;
  1115.  
  1116.         for (i = 0; i < term.t_nrow; ++i) {
  1117.                 vp1 = vscreen[i];
  1118.  
  1119.                 /* for each line that needs to be updated*/
  1120.                 if (vp1->v_flag & VFCHG) {
  1121. #if     TYPEAH
  1122.                         if (force == FALSE && typahead())
  1123.                                 return;
  1124. #endif
  1125. #if     MEMMAP
  1126.                         update_line(i, vp1);
  1127. #else
  1128.                         update_line(i, vp1, pscreen[i]);
  1129. #endif
  1130.                 }
  1131.         }
  1132.         return;
  1133. }
  1134.  
  1135. /*      updext: update the extended line which the cursor is currently
  1136.                 on at a column greater than the terminal width. The line
  1137.                 will be scrolled right or left to let the user see where
  1138.                 the cursor is
  1139.                                                                 */
  1140. VOID PASCAL NEAR updext()
  1141.  
  1142. {
  1143.         register int rcursor;   /* real cursor location */
  1144.         register LINE *lp;      /* pointer to current line */
  1145.         register int j;         /* index into line */
  1146.  
  1147.         /* calculate what column the real cursor will end up in */
  1148.         rcursor = ((curcol - term.t_ncol) % term.t_scrsiz)
  1149.                         + term.t_margin;
  1150.         lbound = curcol - rcursor + 1;
  1151.         taboff = lbound + curwp->w_fcol;
  1152.  
  1153.         /* scan through the line outputing characters to the virtual screen */
  1154.         /* once we reach the left edge                                  */
  1155.         vtmove(currow, -taboff); /* start scanning offscreen */
  1156.         lp = curwp->w_dotp;             /* line to output */
  1157.         for (j=0; j<lused(lp); ++j)     /* until the end-of-line */
  1158.                 vtputc(lgetc(lp, j));
  1159.  
  1160.         /* truncate the virtual line, restore tab offset */
  1161.         vteeol();
  1162.         taboff = 0;
  1163.  
  1164.         /* and put a '$' in column 1 */
  1165.         vscreen[currow]->v_text[0] = '$';
  1166. }
  1167.  
  1168. /*
  1169.  * Update a single line. This does not know how to use insert or delete
  1170.  * character sequences; we are using VT52 functionality. Update the physical
  1171.  * row and column variables. It does try an exploit erase to end of line.
  1172.  */
  1173. #if     MEMMAP
  1174. /*      UPDATE_LINE:    specific code for memory mapped displays */
  1175.  
  1176. VOID PASCAL NEAR update_line(row, vp)
  1177.  
  1178. int row;                /* row of screen to update */
  1179. struct VIDEO *vp;       /* virtual screen image */
  1180.  
  1181. {
  1182. #if     COLOR
  1183.         /* update the color request */
  1184.         vp->v_fcolor = vp->v_rfcolor;
  1185.         vp->v_bcolor = vp->v_rbcolor;
  1186.  
  1187.         /* write the line to the display */
  1188.         scwrite(row, vp->v_text, vp->v_fcolor, vp->v_bcolor,
  1189.                 vp->v_left, vp->v_right);
  1190. #else
  1191.         /* write the line to the display */
  1192.         scwrite(row, vp->v_text, 7, 0, vp->v_left, vp->v_right);
  1193. #endif
  1194.         /* flag this line as changed */
  1195.         vp->v_flag &= ~(VFCHG | VFCOL);
  1196. }
  1197. #else
  1198. VOID PASCAL NEAR update_line(row, vp, pp)
  1199.  
  1200. int row;                /* row of screen to update */
  1201. struct VIDEO *vp;       /* virtual screen image */
  1202. struct VIDEO *pp;       /* physical screen image */
  1203.  
  1204. {
  1205.  
  1206.         register char *vir_left;        /* left pointer to virtual line */
  1207.         register char *phy_left;        /* left pointer to physical line */
  1208.         register char *vir_right;       /* right pointer to virtual line */
  1209.         register char *phy_right;       /* right pointer to physical line */
  1210.         int rev_left;                   /* leftmost reversed char index */
  1211.         int rev_right;                  /* rightmost reversed char index */
  1212.         char *left_blank;               /* left-most trailing blank */
  1213.         int non_blanks;                 /* non-blanks to the right flag */
  1214.         int update_column;              /* update column */
  1215.         int old_rev_state = FALSE;      /* reverse video states */
  1216.         int new_rev_state;
  1217.  
  1218.         /* set up pointers to virtual and physical lines */
  1219.         vir_left = &vp->v_text[0];
  1220.         vir_right = &vp->v_text[term.t_ncol];
  1221.         phy_left = &pp->v_text[0];
  1222.         phy_right = &pp->v_text[term.t_ncol];
  1223.         update_column = 0;
  1224.         rev_left = FARRIGHT;
  1225.         rev_right = 0;
  1226.     non_blanks = TRUE;
  1227.  
  1228.         /* if this is a legitimate line to optimize */
  1229.         if (!(pp->v_flag & VFNEW)) {
  1230.  
  1231.                 /* advance past any common chars at the left */
  1232.                 while ((vir_left != &vp->v_text[term.t_ncol])
  1233.                        && (vir_left[0] == phy_left[0])) {
  1234.                         ++vir_left;
  1235.                         ++update_column;
  1236.                         ++phy_left;
  1237.                 }
  1238.         
  1239. #if     DBCS
  1240.                 /* don't optimize on the left in the middle of a 2 byte char */
  1241.                 if ((vir_left > &vp->v_text[0]) && is2byte(vp->v_text, vir_left - 1)) {
  1242.                         --vir_left;
  1243.                         --update_column;
  1244.                         --phy_left;
  1245.                 }
  1246. #endif
  1247.                 
  1248.                 /* advance past any common chars at the right */
  1249.                 non_blanks = FALSE;
  1250.                 while ((vir_right[-1] == phy_right[-1]) &&
  1251.                        (vir_right >= vir_left)) {
  1252.                         --vir_right;
  1253.                         --phy_right;
  1254.  
  1255.                         /* Note if any nonblank in right match. */
  1256.                         if (vir_right[0] != ' ')
  1257.                                 non_blanks = TRUE;
  1258.                 }
  1259.         
  1260. #if     DBCS
  1261.                 /* don't stop in the middle of a 2 byte char */
  1262.                 if (is2byte(vp->v_text, vir_right-1) || is2byte(pp->v_text, phy_right-1)) {
  1263.                         ++vir_right;
  1264.                         ++phy_right;
  1265.                 }
  1266. #endif
  1267.         }
  1268.  
  1269. #if     COLOR
  1270.         /* new line color? */
  1271.         if (((vp->v_rfcolor != vp->v_fcolor) ||
  1272.             (vp->v_rbcolor != vp->v_bcolor))) {
  1273.                 vp->v_fcolor = vp->v_rfcolor;
  1274.                 vp->v_bcolor = vp->v_rbcolor;
  1275.                 vp->v_flag &= ~VFCOL;
  1276.                 vir_left = &vp->v_text[0];
  1277.                 vir_right = &vp->v_text[term.t_ncol];
  1278.                 phy_left = &pp->v_text[0];
  1279.                 phy_right = &pp->v_text[term.t_ncol];
  1280.                 update_column = 0;
  1281.         }
  1282.  
  1283.         TTforg(vp->v_fcolor);
  1284.         TTbacg(vp->v_bcolor);
  1285. #endif
  1286.  
  1287.         /* reverse video changes? */
  1288.         if ((vp->v_left != pp->v_left) || (vp->v_right != pp->v_right)) {
  1289.  
  1290.                 /* adjust leftmost edge */
  1291.                 if (vp->v_left < pp->v_left)
  1292.                         rev_left = vp->v_left;
  1293.                 else
  1294.                         rev_left = pp->v_left;
  1295.                 pp->v_left = vp->v_left;
  1296.                 if (rev_left < update_column) {
  1297.                         vir_left = &vp->v_text[rev_left];
  1298.                         phy_left = &pp->v_text[rev_left];
  1299.                         update_column = rev_left;
  1300.                 }
  1301.  
  1302.                 /* adjust rightmost edge */
  1303.                 if (vp->v_right > pp->v_right)
  1304.                         rev_right = vp->v_right;
  1305.                 else
  1306.                         rev_right = pp->v_right;
  1307.                 pp->v_right = vp->v_right;
  1308.                 if (&vp->v_text[rev_right] > vir_right) {
  1309.                         vir_right = &vp->v_text[rev_right];
  1310.                         phy_right = &pp->v_text[rev_right];
  1311.                 }
  1312.         } else {
  1313.                 rev_left = vp->v_left;
  1314.                 rev_right = vp->v_right;
  1315.         }
  1316.  
  1317.         /* if both lines are the same, no update needs to be done */
  1318.         if (!(pp->v_flag & VFNEW) && (vir_left > vir_right)) {
  1319.                 vp->v_flag &= ~VFCHG;   /* flag this line as changed */
  1320.                 return;
  1321.         }
  1322.  
  1323.         left_blank = vir_right;
  1324.  
  1325.         /* Erase to EOL ? */
  1326.         if (non_blanks == FALSE && eolexist == TRUE) {
  1327.                 while (left_blank!=vir_left && left_blank[-1]==' ')
  1328.                         --left_blank;
  1329.  
  1330.                 if (vir_right-left_blank <= 3)          /* Use only if erase is */
  1331.                         left_blank = vir_right;         /* fewer characters. */
  1332.         }
  1333.  
  1334.         /* move to the beginning of the text to update */
  1335.         movecursor(row, update_column);
  1336.  
  1337.         while (vir_left != left_blank) {                /* Ordinary. */
  1338.  
  1339.                 /* are we in a reverse video field? */
  1340.                 if (pp->v_left <= update_column && update_column < pp->v_right)
  1341.                         new_rev_state = TRUE;
  1342.                 else
  1343.                         new_rev_state = FALSE;
  1344.  
  1345.                 /* if moving in or out of rev video, change it */
  1346.                 if (new_rev_state != old_rev_state) {
  1347.                         TTrev(new_rev_state);
  1348.                         old_rev_state = new_rev_state;
  1349.         }
  1350.  
  1351.         /* output the next character! */
  1352.         TTputc(*vir_left);
  1353.         ++ttcol;
  1354.         ++update_column;
  1355.         *phy_left++ = *vir_left++;
  1356.     }
  1357.  
  1358.     if (left_blank != vir_right) {        /* Erase. */
  1359.  
  1360.                 /* are we in a reverse video field? */
  1361.                 if (pp->v_left <= update_column && update_column < pp->v_right)
  1362.                         new_rev_state = TRUE;
  1363.                 else
  1364.                         new_rev_state = FALSE;
  1365.  
  1366.                 /* if moving in or out of rev video, change it */
  1367.                 if (new_rev_state != old_rev_state) {
  1368.                         TTrev(new_rev_state);
  1369.                         old_rev_state = new_rev_state;
  1370.                 }
  1371.  
  1372. #if    TERMCAP
  1373.     /* TERMCAP does not tell us if the current terminal propagates
  1374.        the current attributes to the end of the line when an erase
  1375.        to end of line sequence is sent. Don't let TERMCAP use EEOL
  1376.        if in a reverse video line!  (ARG...Pain....Agony....)      */
  1377.         if (new_rev_state == TRUE)
  1378.             while (update_column++ < term.t_ncol)
  1379.                 TTputc(' ');
  1380.         else
  1381.             TTeeol();
  1382. #else
  1383.         TTeeol();
  1384. #endif
  1385.         while (vir_left != vir_right)
  1386.             *phy_left++ = *vir_left++;
  1387.     }
  1388.  
  1389.     vp->v_flag &= ~VFCHG;        /* flag this line as updated */
  1390.     vp->v_flag &= ~VFCOL;
  1391.  
  1392.     /* Always leave in the default state */
  1393.     if (old_rev_state == TRUE)
  1394.         TTrev(FALSE);
  1395.     return;
  1396. }
  1397. #endif
  1398.  
  1399. /*
  1400.  * Redisplay the mode line for the window pointed to by the "wp". This is the
  1401.  * only routine that has any idea of how the modeline is formatted. You can
  1402.  * change the modeline format by hacking at this routine. Called by "update"
  1403.  * any time there is a dirty window.
  1404.  */
  1405. VOID PASCAL NEAR modeline(wp)
  1406.  
  1407. WINDOW *wp;    /* window to update modeline for */
  1408.  
  1409. {
  1410.     register char *cp;
  1411.     register unsigned char c;
  1412.     register int n;        /* cursor position count */
  1413.     register BUFFER *bp;
  1414.     register int i;        /* loop index */
  1415.     register int lchar;     /* character to draw line in buffer with */
  1416.     register int firstm;    /* is this the first mode? */
  1417.     char tline[NLINE];    /* buffer for part of mode line */
  1418.     char time[6];        /* to hold current time */
  1419.  
  1420.     /* don't bother if there is none! */
  1421.     if (modeflag == FALSE)
  1422.         return;
  1423.  
  1424.     n = wp->w_toprow+wp->w_ntrows;        /* Location. */
  1425.  
  1426. /*
  1427.     Note that we assume that setting REVERSE will cause the terminal
  1428.     driver to draw with the inverted relationship of fcolor and
  1429.     bcolor, so that when we say to set the foreground color to "white"
  1430.     and background color to "black", the fact that "reverse" is
  1431.     enabled means that the terminal driver actually draws "black" on a
  1432.     background of "white".  Makes sense, no?  This way, devices for
  1433.     which the color controls are optional will still get the "reverse"
  1434.     signals.
  1435. */
  1436.  
  1437.     vscreen[n]->v_flag |= VFCHG | VFCOL;    /* Redraw next time. */
  1438.     vscreen[n]->v_left = 0;
  1439.     vscreen[n]->v_right = term.t_ncol;
  1440. #if    COLOR
  1441.     vscreen[n]->v_rfcolor = 7;            /* black on */
  1442.     vscreen[n]->v_rbcolor = 0;            /* white.....*/
  1443. #endif
  1444.     vtmove(n, 0);                /* Seek to right line. */
  1445.     if (wp == curwp)            /* mark the current buffer */
  1446.         lchar = '=';
  1447.     else
  1448. #if    REVSTA
  1449.     if (revexist)
  1450.         lchar = ' ';
  1451.     else
  1452. #endif
  1453.         lchar = '-';
  1454.  
  1455.     bp = wp->w_bufp;
  1456.     if ((bp->b_flag&BFTRUNC) != 0)        /* "#" if truncated */
  1457.         vtputc('#');
  1458.     else
  1459.         vtputc(lchar);
  1460.  
  1461.     if ((bp->b_flag&BFCHG) != 0)        /* "*" if changed. */
  1462.         vtputc('*');
  1463.     else
  1464.         vtputc(lchar);
  1465.  
  1466.     if ((bp->b_flag&BFNAROW) != 0) {        /* "<>" if narrowed */
  1467.         vtputc('<');
  1468.         vtputc('>');
  1469.     } else {
  1470.         vtputc(lchar);
  1471.         vtputc(lchar);
  1472.     }
  1473.  
  1474.     n  = 4;
  1475.     strcpy(tline, " ");             /* Buffer name. */
  1476.     strcat(tline, PROGNAME);
  1477.     strcat(tline, " ");
  1478.     strcat(tline, VERSION);
  1479.     strcat(tline, " ");
  1480.  
  1481.     /* display the time on the bottom most modeline if active */
  1482.     if (timeflag && wp->w_wndp == (WINDOW *)NULL) {
  1483.  
  1484.         /* get the current time/date string */
  1485.         getdtime(time);
  1486.         if (strcmp(time, "") != 0) {
  1487.  
  1488.             /* append the hour/min string */
  1489.             strcat(tline, "[");
  1490.             strcat(tline, time);
  1491.             strcat(tline, "] ");
  1492.             strcpy(lasttime, time);
  1493.         }
  1494.     }
  1495.  
  1496.     /* are we horizontally scrolled? */
  1497.     if (wp->w_fcol > 0) {
  1498.         strcat(tline, "[<");
  1499.         strcat(tline, int_asc(wp->w_fcol));
  1500.         strcat(tline, "]");
  1501.     }
  1502.  
  1503.     /* display the point position in buffer if on current modeline */
  1504.     if (posflag && wp == curwp) {
  1505.  
  1506.          strcat(tline, "L:");
  1507.          strcat(tline, long_asc(getlinenum(bp, wp->w_dotp)));
  1508.          strcat(tline, " C:");
  1509.          strcat(tline, int_asc(getccol(FALSE)));
  1510.          strcat(tline, " ");
  1511.     }
  1512.  
  1513.     /* display the modes */
  1514.     strcat(tline, "(");
  1515.     firstm = TRUE;
  1516.     for (i = 0; i < NUMMODES; i++)    /* add in the mode flags */
  1517.         if (wp->w_bufp->b_mode & (1 << i)) {
  1518.             if (firstm != TRUE)
  1519.                 strcat(tline, " ");
  1520.             firstm = FALSE;
  1521.             strcat(tline, modename[i]);
  1522.         }
  1523.     strcat(tline,") ");
  1524.  
  1525.     cp = &tline[0];
  1526.     while ((c = *cp++) != 0) {
  1527.         vtputc(c);
  1528.         ++n;
  1529.     }
  1530.  
  1531. #if    0    /* display internal modes on modeline */
  1532.     vtputc(lchar);
  1533.     vtputc((wp->w_flag&WFCOLR) != 0  ? 'C' : lchar);
  1534.     vtputc((wp->w_flag&WFMODE) != 0  ? 'M' : lchar);
  1535.     vtputc((wp->w_flag&WFHARD) != 0  ? 'H' : lchar);
  1536.     vtputc((wp->w_flag&WFEDIT) != 0  ? 'E' : lchar);
  1537.     vtputc((wp->w_flag&WFMOVE) != 0  ? 'V' : lchar);
  1538.     vtputc((wp->w_flag&WFFORCE) != 0 ? 'F' : lchar);
  1539.     vtputc(lchar);
  1540.     n += 8;
  1541. #endif
  1542.  
  1543.     vtputc(lchar);
  1544.     vtputc(lchar);
  1545.     vtputc(' ');
  1546.     n += 3;
  1547.     cp = &bp->b_bname[0];
  1548.  
  1549.     while ((c = *cp++) != 0) {
  1550.         vtputc(c);
  1551.         ++n;
  1552.     }
  1553.  
  1554.     vtputc(' ');
  1555.     vtputc(lchar);
  1556.     vtputc(lchar);
  1557.     n += 3;
  1558.  
  1559.     if (bp->b_fname[0] != 0) {    /* File name. */
  1560.         vtputc(' ');
  1561.         ++n;
  1562.         cp = TEXT34;
  1563. /*                   "File: " */
  1564.  
  1565.         while ((c = *cp++) != 0) {
  1566.             vtputc(c);
  1567.             ++n;
  1568.         }
  1569.  
  1570.         cp = &bp->b_fname[0];
  1571.  
  1572.         while ((c = *cp++) != 0) {
  1573.             vtputc(c);
  1574.             ++n;
  1575.             }
  1576.  
  1577.         vtputc(' ');
  1578.         ++n;
  1579.     }
  1580.  
  1581.     while (n < term.t_ncol) {    /* Pad to full width. */
  1582.         vtputc(lchar);
  1583.         ++n;
  1584.     }
  1585. }
  1586.  
  1587. VOID PASCAL NEAR getdtime(ts)    /* get the current display time string */
  1588.  
  1589. char *ts;
  1590.  
  1591. {
  1592.     char buf[80];
  1593.  
  1594.     strcpy(buf, timeset());
  1595.     if (strcmp(buf, errorm) == 0) {
  1596.         *ts = 0;
  1597.         return;
  1598.     }
  1599.  
  1600.     buf[16] = 0;
  1601.     strcpy(ts, &buf[11]);
  1602.     return;
  1603. }
  1604.  
  1605. VOID PASCAL NEAR upmode()    /* update all the mode lines */
  1606.  
  1607. {
  1608.     register WINDOW *wp;
  1609. #if     WINDOW_MSWIN
  1610.     SCREEN  *sp;
  1611.  
  1612.     /* loop through all screens to update even partially hidden ones.
  1613.        Note that we process the "first" screen last */
  1614.     sp = first_screen;
  1615.     do {
  1616.         sp = sp->s_next_screen;
  1617.         if (sp == (SCREEN *)NULL) sp = first_screen;
  1618.         vtscreen (sp);
  1619.         wheadp = sp->s_first_window;
  1620. #endif
  1621.  
  1622.     wp = wheadp;
  1623.     while (wp != NULL) {
  1624.         wp->w_flag |= WFMODE;
  1625.         wp = wp->w_wndp;
  1626.     }
  1627. #if     WINDOW_MSWIN
  1628.     } while (sp != first_screen);
  1629. #endif
  1630. }
  1631.  
  1632. VOID PASCAL NEAR upwind()    /* force hard updates on all windows */
  1633.  
  1634. {
  1635.     register WINDOW *wp;
  1636. #if     WINDOW_MSWIN
  1637.     SCREEN  *sp;
  1638.  
  1639.     /* loop through all screens to update even partially hidden ones.
  1640.        Note that we process the "first" screen last */
  1641.     sp = first_screen;
  1642.     do {
  1643.         sp = sp->s_next_screen;
  1644.         if (sp == (SCREEN *)NULL) sp = first_screen;
  1645.         vtscreen (sp);
  1646.         wheadp = sp->s_first_window;
  1647. #endif
  1648.  
  1649.     wp = wheadp;
  1650.     while (wp != NULL) {
  1651.         wp->w_flag |= WFHARD|WFMODE;
  1652.         wp = wp->w_wndp;
  1653.     }
  1654. #if     WINDOW_MSWIN
  1655.     } while (sp != first_screen);
  1656. #endif
  1657. }
  1658.  
  1659. /*
  1660.  * Send a command to the terminal to move the hardware cursor to row "row"
  1661.  * and column "col". The row and column arguments are origin 0. Optimize out
  1662.  * random calls. Update "ttrow" and "ttcol".
  1663.  */
  1664. VOID PASCAL NEAR movecursor(row, col)
  1665.  
  1666. int row, col;
  1667.  
  1668. {
  1669. #if     WINDOW_MSWIN
  1670.     /* emphasize move into message line to avoid confusion with
  1671.        another, larger, screen */
  1672.     if (row >= term.t_nrow)
  1673.         row = term.t_mrow;
  1674.  
  1675.     /* a pending update could move the cursor somewhere else, so
  1676.        we make sure it can't happen */
  1677.     if (defferupdate)
  1678.         update (TRUE);
  1679.  
  1680.     /* in MSWIN, the message line is a separate entity and a call to
  1681.        vtscreen after a movecursor calls might actually have "stolen" the
  1682.        cursor away from the message line! */
  1683.     if (row!=ttrow || col!=ttcol || foulcursor) {
  1684.         foulcursor = FALSE;
  1685. #else
  1686.     /* only move it if there is a difference */
  1687.     if (row != ttrow || col != ttcol) {
  1688. #endif
  1689.         ttrow = row;
  1690.         ttcol = col;
  1691.         TTmove(row, col);
  1692.     }
  1693. }
  1694.  
  1695. /*
  1696.  * Erase the message line. This is a special routine because the message line
  1697.  * is not considered to be part of the virtual screen. It always works
  1698.  * immediately; the terminal buffer is flushed via a call to the flusher.
  1699.  */
  1700.  
  1701. VOID PASCAL NEAR mlferase()
  1702.  
  1703. {
  1704.     register int save_discmd;
  1705.  
  1706.     save_discmd = discmd;
  1707.     discmd = TRUE;
  1708.     mlerase();
  1709.     discmd = save_discmd;;
  1710. }
  1711.  
  1712. VOID PASCAL NEAR mlerase()
  1713.  
  1714. {
  1715.     int i;
  1716.     
  1717.     movecursor(term.t_nrow, 0);
  1718.     if (discmd == FALSE)
  1719.         return;
  1720.  
  1721. #if    COLOR
  1722.     TTforg(gfcolor);
  1723.     TTbacg(gbcolor);
  1724. #endif
  1725.  
  1726.     if (eolexist == TRUE)
  1727.         TTeeol();
  1728.     else {
  1729.         for (i = 0; i < term.t_ncol - 1; i++)
  1730.             TTputc(' ');
  1731.  
  1732.         /* force the move! */
  1733. /*        movecursor(term.t_nrow, 1);*/
  1734.         movecursor(term.t_nrow, 0);
  1735.     }
  1736.     TTflush();
  1737.     mpresf = FALSE;
  1738. }
  1739.  
  1740. /*
  1741.  * Write a message into the message line. Keep track of the physical cursor
  1742.  * position. A small class of printf like format items is handled. Assumes the
  1743.  * stack grows down; this assumption is made by the "+=" in the argument scan
  1744.  * loop. If  STACK_GROWS_UP  is set in estruct.h, then we'll assume that the
  1745.  * stack grows up and use "-=" instead of "+=". Set the "message line"
  1746.  *  flag TRUE.  Don't write beyond the end of the current terminal width.
  1747.  */
  1748.  
  1749. VOID PASCAL NEAR mlout(c)
  1750.  
  1751. int c;    /* character to write */
  1752.  
  1753. {
  1754. #if WINDOW_MSWIN
  1755.     if (ttcol + 1 < NSTRING)
  1756. #else
  1757.     if (ttcol + 1 < term.t_ncol)
  1758. #endif
  1759.         TTputc(c);
  1760.     if (c != '\b')
  1761.         *lastptr++ = c;
  1762.     else if (lastptr > &lastmesg[0])
  1763.         --lastptr;
  1764. }
  1765.  
  1766. #if    VARARG
  1767. #if    VARG
  1768. VOID CDECL NEAR mlwrite(va_alist)
  1769.  
  1770. va_dcl        /* variable argument list
  1771.             arg1 = format string
  1772.             arg2+ = arguments in that string */
  1773.  
  1774. {
  1775.     register int c;     /* current char in format string */
  1776.     register char *fmt;    /* ptr to format string */
  1777.     register va_list ap;    /* ptr to current data field */
  1778.     int arg_int;        /* integer argument */
  1779.     long arg_long;        /* long argument */
  1780.     char *arg_str;        /* string argument */
  1781.  
  1782.     /* if we are not currently echoing on the command line, abort this */
  1783.     if (discmd == FALSE)
  1784.         return;
  1785.  
  1786. #if    COLOR
  1787.     /* set up the proper colors for the command line */
  1788.     TTforg(gfcolor);
  1789.     TTbacg(gbcolor);
  1790. #endif
  1791.  
  1792.     /* point to the first argument */
  1793.     va_start(ap);
  1794.     fmt = va_arg(ap, char *);
  1795.  
  1796.     /* if we can not erase to end-of-line, do it manually */
  1797.     if (eolexist == FALSE) {
  1798.         mlerase();
  1799.         TTflush();
  1800.     }
  1801.  
  1802.     movecursor(term.t_nrow, 0);
  1803.      lastptr = &lastmesg[0];        /* setup to record message */
  1804.     while ((c = *fmt++) != 0) {
  1805.         if (c != '%') {
  1806.             mlout(c);
  1807.             ++ttcol;
  1808.         } else {
  1809.             c = *fmt++;
  1810.             switch (c) {
  1811.                 case 'd':
  1812.                     arg_int = va_arg(ap, int);
  1813.                     mlputi(arg_int, 10);
  1814.                     break;
  1815.  
  1816.                 case 'o':
  1817.                     arg_int = va_arg(ap, int);
  1818.                     mlputi(arg_int, 8);
  1819.                     break;
  1820.  
  1821.                 case 'x':
  1822.                     arg_int = va_arg(ap, int);
  1823.                     mlputi(arg_int, 16);
  1824.                     break;
  1825.  
  1826.                 case 'D':
  1827.                     arg_long = va_arg(ap, long);
  1828.                     mlputli(arg_long, 10);
  1829.                     break;
  1830.  
  1831.                 case 's':
  1832.                     arg_str = va_arg(ap, char *);
  1833.                     mlputs(arg_str);
  1834.                     break;
  1835.  
  1836.                 case 'f':
  1837.                     arg_int = va_arg(ap, int);
  1838.                     mlputf(arg_int);
  1839.                     break;
  1840.  
  1841.                 default:
  1842.                     mlout(c);
  1843.                     ++ttcol;
  1844.             }
  1845.         }
  1846.     }
  1847.  
  1848.     /* if we can, erase to the end of screen */
  1849.     if (eolexist == TRUE)
  1850.         TTeeol();
  1851.     TTflush();
  1852.     mpresf = TRUE;
  1853.     *lastptr = 0;    /* terminate lastmesg[] */
  1854.     va_end(ap);
  1855. }
  1856. #else
  1857. VOID CDECL NEAR mlwrite(char *fmt, ...)
  1858. /* char * fmt;*/
  1859.  
  1860.         /* variable argument list
  1861.             arg1 = format string
  1862.             arg2+ = arguments in that string */
  1863.  
  1864. {
  1865.     register int c;     /* current char in format string */
  1866.     va_list ap;        /* ptr to current data field */
  1867.     int arg_int;        /* integer argument */
  1868.     long arg_long;        /* long argument */
  1869.     char *arg_str;        /* string argument */
  1870.  
  1871.     /* if we are not currently echoing on the command line, abort this */
  1872.     if (discmd == FALSE)
  1873.         return;
  1874.  
  1875. #if    COLOR
  1876.     /* set up the proper colors for the command line */
  1877.     TTforg(gfcolor);
  1878.     TTbacg(gbcolor);
  1879. #endif
  1880.  
  1881.     /* point to the first argument */
  1882.     va_start(ap, fmt);
  1883.  
  1884.     /* if we can not erase to end-of-line, do it manually */
  1885.     if (eolexist == FALSE) {
  1886.         mlerase();
  1887.         TTflush();
  1888.     }
  1889.  
  1890.     movecursor(term.t_nrow, 0);
  1891.      lastptr = &lastmesg[0];        /* setup to record message */
  1892.     while ((c = *fmt++) != 0) {
  1893.         if (c != '%') {
  1894.             mlout(c);
  1895.             ++ttcol;
  1896.         } else {
  1897.             c = *fmt++;
  1898.             switch (c) {
  1899.                 case 'd':
  1900.                     arg_int = va_arg(ap, int);
  1901.                     mlputi(arg_int, 10);
  1902.                     break;
  1903.  
  1904.                 case 'o':
  1905.                     arg_int = va_arg(ap, int);
  1906.                     mlputi(arg_int, 8);
  1907.                     break;
  1908.  
  1909.                 case 'x':
  1910.                     arg_int = va_arg(ap, int);
  1911.                     mlputi(arg_int, 16);
  1912.                     break;
  1913.  
  1914.                 case 'D':
  1915.                     arg_long = va_arg(ap, long);
  1916.                     mlputli(arg_long, 10);
  1917.                     break;
  1918.  
  1919.                 case 's':
  1920.                     arg_str = va_arg(ap, char *);
  1921.                     mlputs(arg_str);
  1922.                     break;
  1923.  
  1924.                 case 'f':
  1925.                     arg_int = va_arg(ap, int);
  1926.                     mlputf(arg_int);
  1927.                     break;
  1928.  
  1929.                 default:
  1930.                     mlout(c);
  1931.                     ++ttcol;
  1932.             }
  1933.         }
  1934.     }
  1935.  
  1936.     /* if we can, erase to the end of screen */
  1937.     if (eolexist == TRUE)
  1938.         TTeeol();
  1939.     TTflush();
  1940.     mpresf = TRUE;
  1941.     *lastptr = 0;    /* terminate lastmesg[] */
  1942.     va_end(ap);
  1943. }
  1944. #endif
  1945. #else
  1946.  
  1947. #if    STACK_GROWS_UP
  1948. #define    ADJUST(ptr, dtype)    ptr -= sizeof(dtype)
  1949. #else
  1950. #define    ADJUST(ptr, dtype)    ptr += sizeof(dtype)
  1951. #endif
  1952.  
  1953. VOID CDECL NEAR mlwrite(fmt)
  1954.  
  1955. char *fmt;    /* format string for output */
  1956.  
  1957. {
  1958.     register int c;     /* current char in format string */
  1959.     register char *ap;    /* ptr to current data field */
  1960.  
  1961.     /* if we are not currently echoing on the command line, abort this */
  1962.     if (discmd == FALSE)
  1963.         return;
  1964.  
  1965. #if    COLOR
  1966.     /* set up the proper colors for the command line */
  1967.     TTforg(gfcolor);
  1968.     TTbacg(gbcolor);
  1969. #endif
  1970.  
  1971.     /* point to the first argument */
  1972.     ap = &fmt;
  1973.     ADJUST(ap, char *);
  1974.  
  1975.     /* if we can not erase to end-of-line, do it manually */
  1976.     if (eolexist == FALSE) {
  1977.         mlerase();
  1978.         TTflush();
  1979.     }
  1980.  
  1981.     movecursor(term.t_nrow, 0);
  1982.      lastptr = &lastmesg[0];        /* setup to record message */
  1983.     while ((c = *fmt++) != 0) {
  1984.         if (c != '%') {
  1985.             mlout(c);
  1986.             ++ttcol;
  1987.         } else {
  1988.             c = *fmt++;
  1989.             switch (c) {
  1990.                 case 'd':
  1991.                     mlputi(*(int *)ap, 10);
  1992.                             ADJUST(ap, int);
  1993.                     break;
  1994.  
  1995.                 case 'o':
  1996.                     mlputi(*(int *)ap,  8);
  1997.                     ADJUST(ap, int);
  1998.                     break;
  1999.  
  2000.                 case 'x':
  2001.                     mlputi(*(int *)ap, 16);
  2002.                     ADJUST(ap, int);
  2003.                     break;
  2004.  
  2005.                 case 'D':
  2006.                     mlputli(*(long *)ap, 10);
  2007.                     ADJUST(ap, long);
  2008.                     break;
  2009.  
  2010.                 case 's':
  2011.                     mlputs(*(char **)ap);
  2012.                     ADJUST(ap, char *);
  2013.                     break;
  2014.  
  2015.                 case 'f':
  2016.                     mlputf(*(int *)ap);
  2017.                     ADJUST(ap, int);
  2018.                     break;
  2019.  
  2020.                 default:
  2021.                     mlout(c);
  2022.                     ++ttcol;
  2023.             }
  2024.         }
  2025.     }
  2026.  
  2027.     /* if we can, erase to the end of screen */
  2028.     if (eolexist == TRUE)
  2029.         TTeeol();
  2030.     TTflush();
  2031.     mpresf = TRUE;
  2032.     *lastptr = 0;    /* terminate lastmesg[] */
  2033. }
  2034. #endif
  2035. /*    Force a string out to the message line regardless of the
  2036.     current $discmd setting. This is needed when $debug is TRUE
  2037.     and for the write-message and clear-message-line commands
  2038. */
  2039.  
  2040. VOID PASCAL NEAR mlforce(s)
  2041.  
  2042. char *s;    /* string to force out */
  2043.  
  2044. {
  2045.     register int oldcmd;    /* original command display flag */
  2046.  
  2047.     oldcmd = discmd;    /* save the discmd value */
  2048.     discmd = TRUE;        /* and turn display on */
  2049.     mlwrite(s);        /* write the string out */
  2050.     discmd = oldcmd;    /* and restore the original setting */
  2051. }
  2052.  
  2053. #if     !WINDOW_MSWIN
  2054. /* display a serious error message (like "out of memory"). This is
  2055.    replaced by a system-specific function when a multitasking system
  2056.    that does not like these kind of errors is used, so that the user can
  2057.    be offered to abort the application */
  2058.  
  2059. VOID PASCAL NEAR mlabort(s)
  2060. char *s;
  2061. {
  2062.     mlforce(s);
  2063. }
  2064. #endif
  2065.  
  2066. /*
  2067.  * Write out a string. Update the physical cursor position. This assumes that
  2068.  * the characters in the string all have width "1"; if this is not the case
  2069.  * things will get screwed up a little.
  2070.  */
  2071.  
  2072. VOID PASCAL NEAR mlputs(s)
  2073.  
  2074. char *s;
  2075.  
  2076. {
  2077.     register int c;
  2078.  
  2079.     while ((c = *s++) != 0) {
  2080.         mlout(c);
  2081.         ++ttcol;
  2082.     }
  2083. }
  2084.  
  2085. /*
  2086.  * Write out an integer, in the specified radix. Update the physical cursor
  2087.  * position.
  2088.  */
  2089. VOID PASCAL NEAR mlputi(i, r)
  2090.  
  2091. int i, r;
  2092.  
  2093.     {
  2094.     register int q;
  2095.     static char hexdigits[] = "0123456789ABCDEF";
  2096.  
  2097.     if (i < 0)
  2098.     {
  2099.     i = -i;
  2100.     mlout('-');
  2101.     }
  2102.  
  2103.     q = i/r;
  2104.  
  2105.     if (q != 0)
  2106.     mlputi(q, r);
  2107.  
  2108.     mlout(hexdigits[i%r]);
  2109.     ++ttcol;
  2110.     }
  2111.  
  2112. /*
  2113.  * do the same except as a long integer.
  2114.  */
  2115. VOID PASCAL NEAR mlputli(l, r)
  2116.  
  2117. long l;
  2118. int r;
  2119.  
  2120.     {
  2121.     register long q;
  2122.  
  2123.     if (l < 0)
  2124.     {
  2125.     l = -l;
  2126.     mlout('-');
  2127.     }
  2128.  
  2129.     q = l/r;
  2130.  
  2131.     if (q != 0)
  2132.     mlputli(q, r);
  2133.  
  2134.     mlout((int)(l%r)+'0');
  2135.     ++ttcol;
  2136.     }
  2137.  
  2138. /*
  2139.  *    write out a scaled integer with two decimal places
  2140.  */
  2141.  
  2142. VOID PASCAL NEAR mlputf(s)
  2143.  
  2144. int s;    /* scaled integer to output */
  2145.  
  2146. {
  2147.     int i;    /* integer portion of number */
  2148.     int f;    /* fractional portion of number */
  2149.  
  2150.     /* break it up */
  2151.     i = s / 100;
  2152.     f = s % 100;
  2153.  
  2154.     /* send out the integer portion */
  2155.     mlputi(i, 10);
  2156.     mlout('.');
  2157.     mlout((f / 10) + '0');
  2158.     mlout((f % 10) + '0');
  2159.     ttcol += 3;
  2160. }
  2161.